package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.WisdomTrails;
import com.dwxt.sport.business.entity.WisdomTrailsEquipment;
import com.dwxt.sport.business.service.WisdomTrailsService;
import com.dwxt.sport.business.vo.wisdomTrails.InsertOrUpdateWisdomTrailsEquipmentVo;
import com.dwxt.sport.business.vo.wisdomTrails.InsertOrUpdateWisdomTrailsVo;
import com.dwxt.sport.business.vo.wisdomTrails.SelectWisdomTrailsVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 智慧步道
 *
 * @author Kuang.JiaZhuo
 * @date 2020-07-31 15:25
 */
@RestController
@RequestMapping("/wisdomTrails")
@Api(tags={"智慧步道相关接口"})
public class WisdomTrailsController {

    @Resource
    WisdomTrailsService wisdomTrailsService;

    @ApiOperation(value = "新增或修改智慧步道", notes = "新增或修改智慧步道", response = Integer.class)
    @PostMapping("/back/insertOrUpdateWisdomTrails")
    public BaseResult insertOrUpdateWisdomTrails(InsertOrUpdateWisdomTrailsVo insertOrUpdateVo){
        int result = this.wisdomTrailsService.insertOrUpdateWisdomTrails(insertOrUpdateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "获取智慧步道列表", notes = "按条件查询智慧步道列表(带分页)", response = WisdomTrails.class)
    @PostMapping("/back/selectWisdomTrailsByCriteria")
    public BaseResult selectWisdomTrailsByCriteria(SelectWisdomTrailsVo selectVo){
        PageInfo<WisdomTrails> pageInfo = this.wisdomTrailsService.selectWisdomTrailsByCriteria(selectVo);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除智慧步道", notes = "根据ids批量删除智慧步道", response= Integer.class)
    @PostMapping(value = "/back/deleteWisdomTrailsByIds")
    public BaseResult deleteWisdomTrailsByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.wisdomTrailsService.deleteWisdomTrailsByIds(ids);
        return BaseResult.ok(result);
    }


    /******************************************************************  关联设备  ******************************************************************************/

    @ApiOperation(value = "新增 或 更新【智慧步道】设备关联", notes = "新增 或 更新【智慧步道】设备关联", response = Integer.class)
    @PostMapping("/back/insertOrUpdateWisdomTrailsEquipment")
    public BaseResult insertOrUpdateWisdomTrailsEquipment(InsertOrUpdateWisdomTrailsEquipmentVo insertOrUpdateVo){
        int result = this.wisdomTrailsService.insertOrUpdateWisdomTrailsEquipment(insertOrUpdateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "删除【智慧步道】设备关联", notes = "根据ids批量删除【智慧步道】设备关联", response= Integer.class)
    @PostMapping(value = "/back/deleteWisdomTrailsEquipmentByIds")
    public BaseResult deleteWisdomTrailsEquipmentByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.wisdomTrailsService.deleteWisdomTrailsEquipmentByIds(ids);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "查询【智慧步道】的设备列表", notes = "根据【智慧步道】的id查询关联设备的列表(带分页)", response= WisdomTrailsEquipment.class)
    @PostMapping(value = "/back/selectWisdomTrailsEquipmentByPage")
    public BaseResult selectWisdomTrailsEquipmentByPage(@ApiParam(value = "智慧步道关联id", required = true) @RequestParam String id,
                                            @ApiParam(value = "起始页", required = true) @RequestParam Integer pageNum,
                                            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize){
        String wisdomTrailsId = id;
        PageInfo<WisdomTrailsEquipment> pageInfo = this.wisdomTrailsService.selectWisdomTrailsEquipmentByPage(pageNum,pageSize,wisdomTrailsId);
        return BaseResult.ok(pageInfo);
    }
}
